package com.cooge.jiexi;

import java.util.HashMap;
import java.util.Random;

import org.apache.http.message.BasicHeader;

import com.alibaba.fastjson.JSONObject;
import com.m1905.mobilefree.h.f;

public class m1905 {

	public static void main(String[] args) throws Exception {
		//Full request URI: http://m.mapps.m1905.cn/Vod/vodDetail?id=882979
		//http://m.mapps.m1905.cn/Vod/download?id=898643&type=2&token=
		
		
		String link = "http://www.1905.com/vod/play/716836.shtml";
		
		int start = link.lastIndexOf("/");
		
		int end = link.lastIndexOf(".");
		
		link = link.substring(start, end).replaceAll("[^0-9]", "");
		
		String url = "http://m.mapps.m1905.cn/Vod/vodDetail?id="+link;
		String did = getImei();
		String md5 = NetUtil.md5(did+""+"m1905_2014");
		System.out.println(md5);
		BasicHeader bh = new BasicHeader("key",md5);
		BasicHeader bh2 = new BasicHeader("did",did);
		BasicHeader bh3 = new BasicHeader("ver","100/41/2015050601");
		BasicHeader bh1 = new BasicHeader("pid","236");
		
		String re_ = NetUtil.postHtml("http://m.mapps.m1905.cn/Member/register",new HashMap<String, String>(),bh1, bh,bh2,bh3);
		String re = NetUtil.getHtml("http://m.mapps.m1905.cn/Index/checkupdate",bh1, bh,bh2,bh3);
		System.out.println("re:"+f.a(re));
		String html = NetUtil.getHtml(url,bh1, bh,bh2,bh3);
		System.out.println(html);
		String source = f.a(html);
		System.out.println(source);
		JSONObject jso =  JSONObject.parseObject(source);
		
		JSONObject data = jso.getJSONObject("data");
		
		if(data.containsKey("soonUrl")){
			String soonUrl = data.getString("soonUrl");
			System.out.println(soonUrl);
		}
		if(data.containsKey("hdUrl")){
			String hdUrl = data.getString("hdUrl");
			System.out.println(hdUrl);
		}
		if(data.containsKey("sdUrl")){
			String sdUrl = data.getString("sdUrl");
			System.out.println(sdUrl);
		}

	}
	
	public static  String  getImei() {
		Random random = new Random();
		Float index = random.nextFloat();
		System.out.println(index);
		String imeiString="8645870290"+String.valueOf(index).replaceAll("[^0-9]", "").substring(1, 5);//前14位
		char[] imeiChar=imeiString.toCharArray();
		int resultInt=0;
		for (int i = 0; i < imeiChar.length; i++) {
			int a=Integer.parseInt(String.valueOf(imeiChar[i]));
			i++;
			final int temp=Integer.parseInt(String.valueOf(imeiChar[i]))*2;
			final int b=temp<10?temp:temp-9;
			resultInt+=a+b;
		}
		resultInt%=10;
		resultInt=resultInt==0?0:10-resultInt;
		return imeiString;
	}
}
